<?php

namespace App\Admin\Controllers\System;

use App\Models\System\Article;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;
use Illuminate\Support\Facades\DB;

class ArticleController extends AdminController
{


    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Article(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('admin_id');
            $grid->column('type');
            $grid->column('title');
            $grid->column('cover');
            $grid->column('is_visible');
            $grid->column('view_cnt');
            $grid->column('good_cnt');
            $grid->column('good_rate');
            $grid->column('weight');
            $grid->column('created_at');
            $grid->model()->orderBy("id",'desc');

    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Article(), function (Show $show) {
            $show->field('id');
            $show->field('type');
            $show->field('cover');
            $show->field('is_visible');
            $show->field('title');
            $show->field('good_cnt');
            $show->field('view_cnt');
            $show->field('good_rate');
            $show->field('is_top');
            $show->field('is_tui');
            $show->field('is_msg');
            $show->field('weight');
            $show->field('url');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Article(), function (Form $form) {
            $form->display('id');
            $form->select('type');
            $form->image('cover');
            $form->text('title');
            $form->text('url');
            $form->text('good_cnt');
            $form->text('view_cnt');
            $form->text('good_rate');
            $form->select('is_top');
            $form->select('is_tui');
            $form->select('is_msg');
            $form->text('weight');
            $form->ueditor('content');
        });
    }
}
